package com.szdtoo.controller;

import com.szdtoo.annotation.CurrentUser;
import com.szdtoo.annotation.SystemLog;
import com.szdtoo.domain.Resource;
import com.szdtoo.domain.User;
import com.szdtoo.response.Result;
import com.szdtoo.service.ResourceService;
import com.szdtoo.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Controller
public class IndexController {

    @Autowired
    private ResourceService resourceService;

    @Autowired
    private UserService userService;

    @SystemLog("默认操作")
    @RequestMapping("/index")
    @ResponseBody
    public Result index() {
        Map<String,Object> map = new HashMap<>();
        String username = (String)SecurityUtils.getSubject().getPrincipal();
        Set<String> permissions = userService.findPermissions(username);
        List<Resource> menus = resourceService.findMenus(permissions);
        map.put("menus",menus);
        return Result.success("操作成功",map);
    }

}
